// components/shippingAddress/shippingAddress.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    addressId: {
      type: String,
      value: '1'
    },
    consignee: {
      type: String,
      value: '许先生'
    },
    mobile: {
      type: String,
      value: '17688729175'
    },
    address: {
      type: String,
      value: '广东省 广州市 番禺区 汉溪大道东362号粤海广场写字楼38层3807室'
    },
    isDefault: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgPath: '/images'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    radioChange(e) {
      console.log("radioChange", e)
    },
    tapDefault(e) {
      console.log("tapDefault", e)
      this.setData({
        isDefault: !this.data.isDefault
      })

      //触发changDefault事件
      this.triggerEvent("changeDefault", {
        id: this.data.id,
        isDefault: this.data.isDefault
      })
    },
    onModify(e) {
      console.log("onModify", e)
      wx.navigateTo({
        url: '/pages/shippingAddress/modify?id=' + this.data.addressId,
      })
    },
    onDelete(e) {
      console.log("onDelete", e)
      wx.showToast({
        title: '删除记录：' + this.data.addressId,
      })
    },
    onItemClick(e) {
      this.triggerEvent("onItemClick", {
        addressId: this.data.addressId,
        consignee: this.data.consignee,
        mobile: this.data.mobile,
        address: this.data.address,
        isDefault: this.data.isDefault
      })
    }
  },
  lifetimes: {
    attached() {
      const util = require("../../utils/util")
      this.setData({
        imgPath: util.getImgPath()
      })
    }
  }
})